var ddf;
$(document).ready(function() { 
	
		ddf=new createObject();
		load(ddf.index.index_js,0,'$ddf_index.loadIndex',"");
		 //加载左边菜单
		 loadMenu();
	}); 


/**
 * 创建全局对象
 */
function createObject() {
		
	
	this.index=new createIndexObject();
	this.account=new createAccountObject();
	this.withDrawSettle=new createWithDrawSettle();//提现
	this.bank = new createBankObject(); //银行的对象
	this.agentMessage = new createAgentMessage(); //创建代理商
	this.shop = new createShop(); //商户
    this.operator = new createOperator(); //操作员查询
    this.terminalControl = new createTerminalControl(); //終端监控
    this.safe = new createSafe(); //安全设置
}



/**
 * 创建用户首页对象
 */
function createIndexObject() {
		
	this.index_js=CTX+"/agent/js/index/index.js";
	this.queryAgentMenus = CTX+"/agent/Login/queryUserMenus.do";
	this.queryShowOperate = CTX +"/agent/Login/queryShowOperate.do";
	this.getAgentTree = CTX +"/agent/Login/getAgentTree.do";
	this.getTerminalByShopId = CTX +"/agent/Login/getTerminalByShopId.do";
	this.agentTree_js = CTX +"/agent/js/agentTree/agentTree.js";
}

/**
 * 创建账户对象
 */
function createAccountObject(){
	this.account_js=CTX+"/agent/js/account/account.js";
	this.getAccountDetails=CTX+"/agent/Account/getAccountDetails.do";
	this.getAccountType= CTX+"/agent/Account/getAccountType.do";
	this.getAccountDetailsById = CTX +"/agent/Account/getAccountDetailsById.do";
}

/**
 * 创建银行的对象
 */
function createBankObject() {
	
	this.bank_js  = CTX + "/agent/js/bank/bank.js"; 
	this.getCardType = CTX + "/agent/Banks/getCardType.do"; //获取身份类型
 	this.getBanksName = CTX + "/agent/Banks/getBanksName.do"; //获取银行的名字
	this.getBindBankCard = CTX + "/agent/Banks/getBindBankCard.do"; //银行绑定
	this.getBankAccountsDetails = CTX + "/agent/Banks/getBankAccountsDetails.do"; //银行账户信息
	this.setDefaultAccounts = CTX +"/agent/Banks/setDefaultAccounts.do"; //设置默认账户
	this.reBindBanks = 	CTX +"/agent/Banks/reBindBanks.do"; //重新绑定
	this.unBindBanks = CTX +"/agent/Banks/unBindBanks.do"; //解除绑定
}

/**
 * 代理商的基本設置
 */
function createAgentMessage(){
	
	this.agentMessage_js = CTX +"/agent/js/agentMessage/agentMessage.js"; //加載代理商戶的基本信息
    this.queryAgent = CTX +"/agent/Agent/queryAgent.do"; //查询代理商消息
    this.saveAgent = CTX + "/agent/Agent/saveAgent.do"; //修改保存代理商信息
//    this.queryShopsByAgentId = CTX +"/agent/Agent/queryShopsByAgentId.do"; 
}

/**
 * 终端监控
 */
function createTerminalControl(){
	this.terminalControl_js = CTX +"/agent/js/terminalControl/terminalControl.js";
	this.queryTerminalByAgentId = CTX+"/agent/Agent/queryTerminalByAgentId.do";
	this.queryTerminalMapByAgentId = CTX +"/agent/Agent/queryTerminalMapByAgentId.do"; //终端控制地图
    this.getShopDetailByShopId = CTX +"/agent/Agent/getShopDetailByShopId.do"; //更具shopId查看商家的详情
 }

/**
 * 操作员对象
 */
function createOperator(){
	this.operator_js = CTX +"/agent/js/operator/operator.js";
	this.queryAllByAgentId = CTX+"/agent/UserAgent/queryAllByAgentId.do";
}
 
/**
 * 安全设置
 */
function createSafe(){
	
	this.safe_js = CTX + "/agent/js/safe/safe.js"; //加载安全设置
	this.queryMessage = CTX +"/agent/SafeSet/queryMessage.do"; //查询用户的基本信息
//	this.showMobile = CTX +"/agent/SafeSet/showMobile.do"; //修改手机
	this.resetMobile = CTX + "/agent/SafeSet/resetMobile.do"; //修改手机
    this.resetLoginPwd = CTX +"/agent/SafeSet/resetLoginPwd.do"; //修改登录密码
    this.resetPayPwd = CTX +"/agent/SafeSet/resetPayPwd.do"; //修改支付密码
	
}

/**
 * 提现的对象
 */
function createWithDrawSettle() {
		
	this.withDrawSettle_js=CTX+"/agent/js/withDrawSettle/withDrawSettle.js"; //提现记录
	
	this.withDraw_js = CTX +"/agent/js/withDrawSettle/withdraw.js"; //提现操作
	
	this.getWithDrawSettleList=CTX+"/agent/Withdraw/querySettle.do";//提现的记录
	
	this.withdraw = CTX+"/agent/Withdraw/withdraw.do"; //提现操作
	
	this.confirm = CTX+"/agent/Withdraw/confirm.do"; //提现确认
	
	this.settleApply = CTX+"/agent/Withdraw/settleApply.do"; //提现申请
	
}
/**
 * 创建商户
 */
function createShop(){
	this.shop_js = CTX+"/agent/js/shop/shop.js";
    this.queryShopsByAgentId = CTX + "/agent/Agent/queryShopsByAgentId.do"; //查询代理商所拥有的商家
}


/**
 * 显示错误信息
 */
function addErrorMessage(control_id,input_id,message){
	
	$("#"+control_id).addClass("error");
	
	$("#"+control_id+" div span.help-inline").html("");
	
	$("#"+input_id).after('<span class="help-inline">'+message+'</span>');
	
}



/**
 * 加载地图
 */
function allmap(id,latitude,longitude) {

	
	if(latitude=="")
		latitude = 34.647653;
	
	if(longitude=="")
		longitude = 112.418722;
	
/* 	var address = "云便利商店"; //默认地址
	var map = new BMap.Map(id); // 创建地图实例  
	var point = new BMap.Point(longitude, latitude); // 创建点坐标  
	map.centerAndZoom(point, 16); // 初始化地图，设置中心点坐标和地图级别  
	map.enableScrollWheelZoom(); //启用滚轮放大缩小
	map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
	var myMarker = new BMap.Marker(point);
	map.addOverlay(myMarker);
	var myGeo = new BMap.Geocoder();
	myGeo.getPoint(address, function(point) {
		if (point) {
			myMarker = new BMap.Marker(point);
			map.centerAndZoom(point, 16);
			map.addOverlay(myMarker);
		}
	}, "广州市");
	 */
	// 百度地图API功能
	var map = new BMap.Map(id);            // 创建Map实例
	map.centerAndZoom(new BMap.Point(longitude,latitude),16);  //初始化时，即可设置中心点和地图缩放级别。
	var point = new BMap.Point(longitude, latitude); // 创建点坐标  
	var myMarker = new BMap.Marker(point);
	map.addOverlay(myMarker);
	
	
	map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
	map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}));  //右上角，仅包含平移和缩放按钮
	map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT, type: BMAP_NAVIGATION_CONTROL_PAN}));  //左下角，仅包含平移按钮
	map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_ZOOM}));  //右下角，仅包含缩放按钮
	
	
	
	/* setTimeout(function(){
	    map.setCenter("广州");   //设置地图中心点。center除了可以为坐标点以外，还支持城市名
	    map.setZoom(10);  //将视图切换到指定的缩放等级，中心点坐标不变    
	}, 1500);
	 */
	
	map.addEventListener("click", function(e) {//地图单击事件
		if (myMarker != null) {
			map.removeOverlay(myMarker);
		}
		document.getElementById("input-longitude").value = e.point.lng;
		document.getElementById("input-latitude").value = e.point.lat;
		point = new BMap.Point(e.point.lng, e.point.lat);
		myMarker = new BMap.Marker(point);
		map.addOverlay(myMarker);
	});
}


/**
 * 清除错误信息
 */
function clearErrorMessage(id){
	
	$("#"+id).removeClass("error");
	
	$("#"+id+" div span").remove();
}



//修改成功提示
function tips(index,text){
	
	$("#alert-tips"+index).html('<div class="alert alert-block alert-success alert-tips"><a class="close" data-dismiss="alert" href="#">×</a><h4 class="alert-heading">'+text+'</h4></div>');
	$(".alert-tips").fadeIn(100);
	setTimeout(function(){$(".alert-tips").fadeOut(500);},1000);	
}

//失败提示
function tips_error(index,text){
	$("#alert-tips"+index).html('<div class="alert alert-block alert-error alert-tips"><a class="close" data-dismiss="alert" href="#">×</a><h4 class="alert-heading">'+text+'</h4></div>');
	$(".alert-tips").fadeIn(100);
	setTimeout(function(){$(".alert-tips").fadeOut(500);},1000);	
}

//等待加载（刷新）
function loading_box(){
	$(".loading_box").addClass("waiting");	
}
function remove_waiting(){
	$(".loading_box").removeClass("waiting");	
}

/**
 * 显示加载框
 */
function showLoading(){
	
	$("#wait").css("display","block");
}

/**
 * 取消加载框
 */
function cancelLoading(){
	
	$("#wait").css("display","none");
}

Array.prototype.del=function(n){
	
	if(n<0){
		return this;
	}else
		return this.slice(0, n).concat(this.slice(n+1,this.length));
}
